import axios from "axios"
// 基础配置，时间
const _axios = axios.create({
  timeout: 5 * 60 * 1000, // 超时时间 
  // baseURL:'http://101.43.171.167/api',
  // baseURL:'/api',
  baseURL:process.env.VUE_APP_BASE_URL, // url = base url + request url,
})
let token = localStorage.getItem('token')
// 在发送请求之前
_axios.interceptors.request.use(config => {
  if(token){
    config.headers.common['token'] = token
  }
  return config
}, err => {
  return Promise.reject(err);
});

// http response 拦截器
_axios.interceptors.response.use(response => {
    return response.data
  },
  error => {
    console.log(error)
    return Promise.reject(error.response.data)
})

export default _axios